package com.key.activity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.key.util.Util;
import com.key.wanderbupt.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter {
	
	public List<String> list = new ArrayList<String>();
	
	private LayoutInflater inflater = null;
	
	public static Map<Integer,Boolean> checkboxMap = new TreeMap<Integer,Boolean>();
	
	public ListViewAdapter(Context context, List<String> items) {
		this.list = items;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		initCheckboxMap();
	}
	
	private void initCheckboxMap() {
		checkboxMap.clear();
		for( int i=0; i<list.size(); i++ ) {
			checkboxMap.put(i, false);
		}
	}
	
	public int getCount() {

		return list.size();
	}

	public Object getItem(int position) {
		
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
	
	public static class ViewHolder {  
        public TextView title;
    }

	public View getView( int position, View view, ViewGroup parent ) {
		
		ViewHolder holder = null;
		
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.key_item, null);
			holder.title = (TextView) view.findViewById(R.id.buildingtitle);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		
		holder.title.setText((String) Util.result[position]);
        
		return view;
	}
}
